/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.unitedats.Project.Entity;


import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import com.unitedats.HR.Entity.HrEmployee;
import com.unitedats.common.util.SearchRequired;

/**
 *
 * @author Awad
 */
@Entity
@Table(name = "pm_project")
@XmlRootElement
@NamedQueries({
              @NamedQuery(name = "PmProject.findAll", query = "SELECT p FROM PmProject p"),
              @NamedQuery(name = "PmProject.findById", query = "SELECT p FROM PmProject p WHERE p.id = :id"),
              @NamedQuery(name = "PmProject.findByName", query = "SELECT p FROM PmProject p WHERE p.name = :name"),
              @NamedQuery(name = "PmProject.findByCode", query = "SELECT p FROM PmProject p WHERE p.code = :code"),
              @NamedQuery(name = "PmProject.findByTypeId",
                          query = "SELECT p FROM PmProject p WHERE p.typeId = :typeId"),
              @NamedQuery(name = "PmProject.findByStatusId",
                          query = "SELECT p FROM PmProject p WHERE p.statusId = :statusId"),
              @NamedQuery(name = "PmProject.findByPlannedStartDate",
                          query = "SELECT p FROM PmProject p WHERE p.plannedStartDate = :plannedStartDate"),
              @NamedQuery(name = "PmProject.findByPlannedEndDate",
                          query = "SELECT p FROM PmProject p WHERE p.plannedEndDate = :plannedEndDate"),
              @NamedQuery(name = "PmProject.findByActualStartDae",
                          query = "SELECT p FROM PmProject p WHERE p.actualStartDae = :actualStartDae"),
              @NamedQuery(name = "PmProject.findByActualEndDate",
                          query = "SELECT p FROM PmProject p WHERE p.actualEndDate = :actualEndDate"),
              @NamedQuery(name = "PmProject.findByTotalContractValue",
                          query = "SELECT p FROM PmProject p WHERE p.totalContractValue = :totalContractValue"),
              @NamedQuery(name = "PmProject.findByContractFileUrl",
                          query = "SELECT p FROM PmProject p WHERE p.contractFileUrl = :contractFileUrl"),
              @NamedQuery(name = "PmProject.findByPoUrl", query = "SELECT p FROM PmProject p WHERE p.poUrl = :poUrl"),
              @NamedQuery(name = "PmProject.findByContractNo",
                          query = "SELECT p FROM PmProject p WHERE p.contractNo = :contractNo"),
              @NamedQuery(name = "PmProject.findByCreatedIn",
                          query = "SELECT p FROM PmProject p WHERE p.createdIn = :createdIn"),
              @NamedQuery(name = "PmProject.findByLastModifiedIn",
                          query = "SELECT p FROM PmProject p WHERE p.lastModifiedIn = :lastModifiedIn")
    })
public class PmProject implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    //@Basic(optional = false)
    @Column(name = "id")
    @SearchRequired
    private Integer id;
    //@Basic(optional = false)
    @Column(name = "name")
    @SearchRequired    
    private String name;
    //@Basic(optional = false)
    @Column(name = "code")
    @SearchRequired
    private String code;
    //@Basic(optional = false)
    @Column(name = "type_id")
    private Integer typeId;
    //@Basic(optional = false)
    @Column(name = "status_id")
    private Integer statusId;
    //@Basic(optional = false)
    @Column(name = "planned_start_date")
    @Temporal(TemporalType.DATE)
    private Date plannedStartDate;
  //  //@Basic(optional = false)
    @Column(name = "planned_end_date")
    @Temporal(TemporalType.DATE)
    private Date plannedEndDate;
    //@Basic(optional = false)
    @Column(name = "actual_start_dae")
    @Temporal(TemporalType.DATE)
    private Date actualStartDae;
    //@Basic(optional = false)
    @Column(name = "actual_end_date")
    @Temporal(TemporalType.DATE)
    private Date actualEndDate;
    //@Basic(optional = false)
    @Column(name = "total_contract_value")
    private Float totalContractValue;
    //@Basic(optional = false)
    @Column(name = "contract_file_url")
    private String contractFileUrl;
    //@Basic(optional = false)
    @Column(name = "po_url")
    private String poUrl;
    //@Basic(optional = false)
    @Column(name = "contract_no")
    private String contractNo;
    @Basic(optional = true)
    @Column(name = "created_in")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdIn;
    @Basic(optional = true)
    @Column(name = "last_modified_in")
    @Temporal(TemporalType.TIMESTAMP)
    private Date lastModifiedIn;
    @JoinColumn(name = "last_modified_by", referencedColumnName = "id")
    @ManyToOne(optional = true)
    private HrEmployee lastModifiedBy;
    @JoinColumn(name = "created_by", referencedColumnName = "id")
    @ManyToOne(optional = true)
    private HrEmployee createdBy;
    @JoinColumn(name = "contract_currentcy_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private LookupCurrency contractCurrentcyId;
    @JoinColumn(name = "country_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private LookupCountry countryId;
    
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "projectId", orphanRemoval = true)
	@LazyCollection(LazyCollectionOption.FALSE)
    private List<PmProjectPartner> pmProjectPartnerList;
    
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "projectId", orphanRemoval = true)
	@LazyCollection(LazyCollectionOption.FALSE)
    private List<PmProjectMember> pmProjectMemberList;

    public PmProject() {
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Integer getTypeId() {
        return typeId;
    }

    public void setTypeId(Integer typeId) {
        this.typeId = typeId;
    }

    public Integer getStatusId() {
        return statusId;
    }

    public void setStatusId(Integer statusId) {
        this.statusId = statusId;
    }

    public Date getPlannedStartDate() {
        return plannedStartDate;
    }

    public void setPlannedStartDate(Date plannedStartDate) {
        this.plannedStartDate = plannedStartDate;
    }

    public Date getPlannedEndDate() {
        return plannedEndDate;
    }

    public void setPlannedEndDate(Date plannedEndDate) {
        this.plannedEndDate = plannedEndDate;
    }

    public Date getActualStartDae() {
        return actualStartDae;
    }

    public void setActualStartDae(Date actualStartDae) {
        this.actualStartDae = actualStartDae;
    }

    public Date getActualEndDate() {
        return actualEndDate;
    }

    public void setActualEndDate(Date actualEndDate) {
        this.actualEndDate = actualEndDate;
    }

    public Float getTotalContractValue() {
        return totalContractValue;
    }

    public void setTotalContractValue(Float totalContractValue) {
        this.totalContractValue = totalContractValue;
    }

    public String getContractFileUrl() {
        return contractFileUrl;
    }

    public void setContractFileUrl(String contractFileUrl) {
        this.contractFileUrl = contractFileUrl;
    }

    public String getPoUrl() {
        return poUrl;
    }

    public void setPoUrl(String poUrl) {
        this.poUrl = poUrl;
    }

    public String getContractNo() {
        return contractNo;
    }

    public void setContractNo(String contractNo) {
        this.contractNo = contractNo;
    }

    public Date getCreatedIn() {
        return createdIn;
    }

    public void setCreatedIn(Date createdIn) {
        this.createdIn = createdIn;
    }

    public Date getLastModifiedIn() {
        return lastModifiedIn;
    }

    public void setLastModifiedIn(Date lastModifiedIn) {
        this.lastModifiedIn = lastModifiedIn;
    }

    public HrEmployee getLastModifiedBy() {
        return lastModifiedBy;
    }

    public void setLastModifiedBy(HrEmployee lastModifiedBy) {
        this.lastModifiedBy = lastModifiedBy;
    }

    public HrEmployee getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(HrEmployee createdBy) {
        this.createdBy = createdBy;
    }

    public LookupCurrency getContractCurrentcyId() {
        return contractCurrentcyId;
    }

    public void setContractCurrentcyId(LookupCurrency contractCurrentcyId) {
        this.contractCurrentcyId = contractCurrentcyId;
    }

    public LookupCountry getCountryId() {
        return countryId;
    }

    public void setCountryId(LookupCountry countryId) {
        this.countryId = countryId;
    }

    @XmlTransient
    public List<PmProjectPartner> getPmProjectPartnerList() {
        return pmProjectPartnerList;
    }

    public void setPmProjectPartnerList(List<PmProjectPartner> pmProjectPartnerList) {
        this.pmProjectPartnerList = pmProjectPartnerList;
    }

    @XmlTransient
    public List<PmProjectMember> getPmProjectMemberList() {
        return pmProjectMemberList;
    }

    public void setPmProjectMemberList(List<PmProjectMember> pmProjectMemberList) {
        this.pmProjectMemberList = pmProjectMemberList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PmProject)) {
            return false;
        }
        PmProject other = (PmProject) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }


    @Override
    public String toString() {
        return "com.unitedats.Project.Entity.PmProject[ id=" + id + " ]";
    }
    
    
    public PmProjectMember addPmProjectMember(PmProjectMember pmProjectMember) {
		getPmProjectMemberList().add(pmProjectMember);
		pmProjectMember.setProjectId(this);

		return pmProjectMember;
	}

	public PmProjectMember removePmProjectMember(PmProjectMember pmProjectMember) {
		getPmProjectMemberList().remove(pmProjectMember);
		pmProjectMember.setProjectId(null);

		return pmProjectMember;
	}
	
	public PmProjectPartner addPmProjectPartner(PmProjectPartner pmProjectPartner) {
		getPmProjectPartnerList().add(pmProjectPartner);
		pmProjectPartner.setProjectId(this);

		return pmProjectPartner;
	}

	public PmProjectPartner removePmProjectPartner(PmProjectPartner pmProjectPartner) {
		getPmProjectPartnerList().remove(pmProjectPartner);
		pmProjectPartner.setProjectId(null);

		return pmProjectPartner;
	}

}
